#include<bits/stdc++.h>
#define ll long long
#define mid ((l+r)>>1)
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    void pc(const char *s){
    	while(*s)putch(*s),s++;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x),putch(' '),write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=3005,mod=1e9+7;
int xx[4]={1,-1,0,0};
int yy[4]={0,0,1,-1};
int n,m;
int a[N][N];
void sub1(){
	int cnt=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(a[i][j])continue;
			int flag=0;
			for(int ops=0;ops<4;ops++){
				int _i=i+xx[ops],_j=j+yy[ops];
				if(a[_i][_j])flag=1;
			}
			cnt+=flag;
		}
	}
	write(cnt),putch('\n');
	return;
}
void sub2(){
	int cnt=0,sum=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(a[i][j])continue;
			int flag=0;
			for(int ops=0;ops<4;ops++){
				int _i=i+xx[ops],_j=j+yy[ops];
				if(a[_i][_j]==1)flag=1;
			}
			if(flag){
				cnt++;
				a[i][j]=2;
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(a[i][j]==2){
				for(int ops=0;ops<4;ops++){
					int _i=i+xx[ops],_j=j+yy[ops];
					if(_i<1||_i>n||_j<1||_j>n)continue;
					if(a[_i][_j]==0)sum++;
				}
			}
		}
	}
	write((1ll*cnt*(cnt-1)/2%mod+sum)%mod),putch('\n');
	return;
}
signed main(){
	freopen("brick.in","r",stdin);
	freopen("brick.out","w",stdout);
	read(n,m);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			char ch=getch();
			while(ch!='.'&&ch!='#')ch=getch();
			if(ch=='#')a[i][j]=1;
		}
	}
	if(m==1)sub1();
	else if(m==2)sub2();
	return flush(),0;
}

